package CollectionDemo.ListDemo;

import java.util.*;

public class Traverse {
    public static void main(String[] args) {
        List<String> list1 = new ArrayList<>();
        list1.add("James");
        list1.add("Kobe");
        list1.add("Durant");
        list1.add("Irving");
        System.out.println(list1);
//        List的两种遍历方式：
//        1.迭代器遍历集合Iterator
        Iterator iterator = list1.iterator();
        while (iterator.hasNext()){
            System.out.print(iterator.next() + " ");
        }
        System.out.println();
//        2.foreach增强循环
        for (String string:list1) {
            System.out.print(string + " ");
        }
        System.out.println();

    }
}
